﻿$(document).ready(function () {
   // var timeout = setTimeout(function () { window.location = "http://localhost:3097/"; }, 10000);
    var secounds = 1;
    var chat = $.connection.chatHub;

    $messages = $(".messages");
    $log = $(".log");

    chat.client.connected = function (frm, list, date) {
        if ($("#" + frm).length <= 0) {

            for (i = 0; i < list.length; i++) {
                $("#" + list[i]).remove();
            }

            for (i = 0; i < list.length; i++) {
                $log.append("<span id=" + list[i] + ">" + list[i] + "</span>");
            }
        }
    };

    chat.client.disconnected = function (frm) {
        if ($("#" + frm).length > 0)
            $("#" + frm).remove();
    };

    chat.client.addMessage = function (frm, msg) {
        $messages.append(frm + "  : " + msg + "</br>");
    }

    $(".send").click(function () {
        var input = $(".messagestext").val();
        chat.server.sendMessage(input);

        $(".messagestext").val("");
    });


    $(".messagestext").keypress(function (e) {
        if (e.which == 13) {

            //get value of input
            var input = $(this).val();

            chat.server.sendMessage(input);
            $(this).val("");
        }
    });

    $.connection.hub.start();

  //  setInterval(function () { $("#display-time").text(secounds);  secounds++;}, 1000);

    $('.send').click(function () {
        secounds = 1;
   //     clearTimeout(timeout);
    });
});